package com.lanou3g.ptp.api.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanou3g.ptp.entity.Role;
import com.lanou3g.ptp.entity.School;
import com.lanou3g.ptp.role.RoleService;
import com.lanou3g.utils.PtpResult;
import com.lanou3g.utils.PtpResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("成绩接口")
@RestController
public class RoleController {
    @Reference
    private RoleService roleService;
    @ApiOperation("通过id获取role")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "roleId")
    })
    @GetMapping("/role/{id}")
    public PtpResult findById(@PathVariable Long id) {
        List<Role> role = roleService.findById(id);
        return PtpResultUtils.ok(role);
    }

    @ApiOperation("获取所有的role")
    @GetMapping("/roles")
    public PtpResult findAll(@RequestParam(value = "page",defaultValue = "1") Integer page,
                             @RequestParam(value = "size",defaultValue = "30") Integer size){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<Role> roles = roleService.findAll(page, size);
        return PtpResultUtils.ok(objects);
    }

    @ApiOperation("通过id删除role")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "roleId")
    })
    @DeleteMapping("/role/{id}")
    public PtpResult deleteById(@PathVariable Long id){
        roleService.deleteById(id);
        return PtpResultUtils.ok();
    }
    @ApiOperation("添加一个role")
    @PostMapping("/role")
    public PtpResult add(Role role){
        roleService.addRole(role);
        return PtpResultUtils.ok();
    }
}
